#!/bin/bash
#编辑》》虚拟网络编辑器》》更改设置》》点击VMnet8》》更改子网ip为192.168.227.0 子网掩码为255.255.255.0
#编辑虚拟机设置》》硬件》》网络适配器》》NAT》》高级》》生成MAC地址

# 获取系统是centos6还是7等
sys_byte=$(rpm -qi centos-release | grep Version | tr -c -d [:digit:])

#echo "*******************************************************************************"
#echo "安装wget"
#echo "*******************************************************************************"
yum install wget -y
echo "*******************************************************************************"
echo "安装wget完成"
echo "*******************************************************************************"

#echo "*******************************************************************************"
#echo "备份原先的yum命名为CentOS-Base.repo.日期"
#echo "*******************************************************************************"
cd /etc/yum.repos.d/
cp /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.$(date -d "today" +"%Y%m%d_%H%M%S")

#echo "*******************************************************************************"
#echo "配置yum源为163源"
#echo "*******************************************************************************"
# 获取163repo并命名为CentOS-Base.repo
wget http://mirrors.163.com/.help/CentOS$sys_byte-Base-163.repo &&  rm -f CentOS-Base.repo && mv CentOS$sys_byte-Base-163.repo CentOS-Base.repo
yum clean all 
yum makecache 
yum update
echo "*******************************************************************************"
echo "配置yum源为163源成功，可查看cat /etc/yum.repos.d/CentOS-Base.repo"
echo "*******************************************************************************"

yum install yum-plugin-fastestmirror -y
#echo "*******************************************************************************"
#echo " 配置epel源"
echo "*******************************************************************************"
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
echo "*******************************************************************************"
echo " 配置epel源成功"
echo "*******************************************************************************"

echo "*******************************************************************************"
echo "正在关闭防火墙……"
echo "*******************************************************************************"
systemctl stop firewalld > /dev/null 2>&1
systemctl disable firewalld  > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "防火墙初始化完毕！"
fi

echo "*******************************************************************************"
echo "正在关闭SELinux……"
echo "*******************************************************************************"
setenforce 0 > /dev/null 2>&1
sed -i '/^SELINUX=/s/=.*/=disabled/' /etc/selinux/config
if [ $? -eq 0 ];then
        echo "SELinux初始化完毕！"
fi


echo "*******************************************************************************"
echo "配置静态网络为192.168.227.144……"
echo "*******************************************************************************"
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.227.144
NETMASK=255.255.255.0
GATEWAY=192.168.227.2
DNS2=114.114.114.114
EOF

echo "*******************************************************************************"
echo "重启网络中……,重启机器，重启后请重新修改ssh连接192.168.227.144"
echo "*******************************************************************************"
systemctl restart network
reboot

